package com.wangyadong.hobby.metric.gauge.lession3;

import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.JmxAttributeGauge;
import com.codahale.metrics.MetricRegistry;

import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 *
 * @author <714037465@qq.com>
 * @since 2018/12/1815:56
 **/
public class JMXGaugeExample {

    private final static MetricRegistry registry = new MetricRegistry();

    private final static ConsoleReporter reporter = ConsoleReporter
            .forRegistry(registry)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.SECONDS)
            .build();

    public static void main(String[] args) throws MalformedObjectNameException, InterruptedException {
        reporter.start(10, TimeUnit.SECONDS);
//        registry.register(MetricRegistry.name(JMXGaugeExample.class, "HeapMemory"), new JmxAttributeGauge(
//                new ObjectName("java.lang:type=Memory"), "HeapMemoryUsage"
//        ));

//        registry.register(MetricRegistry.name(JMXGaugeExample.class, "NonHeapMemoryUsage"), new JmxAttributeGauge(
//                new ObjectName("java.lang:type=Memory"), "NonHeapMemoryUsage"
//        ));

        registry.register(MetricRegistry.name(JMXGaugeExample.class,"111"),new JmxAttributeGauge(
                new ObjectName("java.lang:type=GarbageCollector,name=PS MarkSweep"),"PS MarkSweep"
        ));
        Thread.currentThread().join();
    }
}
